home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / daten / quickfile / arexx / setfield.quickfile < prev    next >
Text File  |  1995-04-06  |  3KB  |  139 lines

  1. /*
  2.     SetField.QuickFile
  3.  
  4.     Sets a field in all selected records to a constant value
  5.     Prompts user for field and value and includes checking that
  6.     the requested field name is valid
  7.  
  8.     Author: Alan Wigginton
  9.     Date:   March 1995
  10. */
  11.  
  12. options results
  13.  
  14. if ~open(console,"con:20/40/460/120/SetField","W") then
  15. do
  16.     say "Could not open window"
  17.     exit(20)
  18. end
  19.  
  20. "query field fld"       /* get all the field names in stem fld. */
  21.  
  22. "setindex"              /* get the current index name   */
  23. ixname = result
  24.  
  25. "query index ixfld '"ixname"'"  /* get the index field names    */
  26. if rc > 0 then
  27.     call ErrorProc "Error getting index details"
  28.  
  29. call writeln(console, "Set field to a constant value")
  30. call writeln(console, "- will update all records in the current index")
  31. call writeln(console, "Press RETURN with no value to exit")
  32.  
  33. /*
  34.     Get the field name. Keep trying until the user gets it right
  35.     or they give up (RETURN with no data)
  36. */
  37.  
  38. err = "Y"
  39. do while err = "Y"
  40.     call writeln(console, "What is the field to be changed?")
  41.     ReqFld = upper(readln(console))
  42.     if ReqFld = "" then
  43.     exit
  44.     call CheckFld
  45. end
  46.  
  47. /*
  48.     Get the value to set the field to
  49. */
  50.  
  51. call writeln(console, "Set" ReqFld "to what value")
  52. ReqVal = readln(console)
  53.  
  54. /*
  55.     Confirm operation and number of records to be updated
  56. */
  57.  
  58. "numrecs"       /* ask quickfile for the number of records */
  59. numrecs = result
  60.  
  61. call writeln(console, "About to set" ReqFld "to" ReqVal)
  62. call writeln(console, "in" numrecs "records")
  63. call writeln(console, "Enter Y to continue")
  64. ans = upper(readln(console))
  65. if ans ~= "Y" then
  66. do
  67.     call writeln(console, "Request cancelled - press any key")
  68.     ans = readln(console)
  69.     exit
  70. end
  71.  
  72. "next -32000"       /* This goes to top of file */
  73.  
  74. /*
  75.     Change all the records
  76. */
  77.  
  78. count = 0
  79. eof = "N"
  80. do while eof = "N"
  81.     "putfield '"ReqFld"' '"ReqVal"'"
  82.     if rc > 0 then
  83.     do
  84.     call writeln(console, "Error from putfield after")
  85.     call ErrorProc count "records updated"
  86.     end
  87.     "updrec"        /* commit the update record     */
  88.     if rc > 0 then
  89.     call ErrorProc    "Error updating record"
  90.     count = count + 1
  91.     "next"
  92.     if rc > 0 then
  93.     eof = "Y"
  94. end
  95.  
  96. /*
  97.     Tell the user that we completed it OK
  98. */
  99.  
  100. call writeln(console, count "records updated")
  101. call writeln(console, "Press RETURN to continue")
  102. ans = readln(console)
  103. exit
  104.  
  105.  
  106. /*
  107.     Check that the field name is valid
  108. */
  109.  
  110. CheckFld:
  111.  
  112. do i = 1 to fld.0
  113.     if ReqFld = fld.i then
  114.     do
  115.     err = "N"
  116.     return
  117.     end
  118. end
  119.  
  120. call writeln(console, ReqFld "is unknown")
  121.  
  122. return
  123.  
  124.  
  125. /*
  126.     Display error message and exit
  127.     ------------------------------
  128. */
  129.  
  130. ErrorProc:
  131.  
  132. arg errmsg
  133.  
  134. call writeln(console, errmsg)
  135. call writeln(console, "Press RETURN to continue")
  136. ans = readln(console)
  137. exit(10)
  138.  
  139.